﻿using OpenTK.Graphics.OpenGL4;

namespace TrinityEngine
{
    public class Texture2D
    {
        public byte[] Data { get; private set; }

        public int Width { get; private set; }

        public int Height { get; private set; }

        public int TextureID { get; private set; }

        public Texture2D(byte[] data, int width, int height)
        {
            Data = data;
            Width = width;
            Height = height;

            TextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, TextureID);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, Data);
            GL.GenerateTextureMipmap(TextureID);
        }

        public void Use()
        {
            GL.BindTexture(TextureTarget.Texture2D, TextureID);
        }
    }
}
